<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      //请实现以下效果
      // function add(x) {
      //   return function (y) {
      //     return function (z) {
      //       return x + y + z
      //     }
      //   }
      // }
      // const res = add(1)(2)(3)
      // console.log(res)

      //求和
      const sumFn = (...args) => {
        return args.reduce((a, b) => {
          return a + b
        })
      }

      let currying = function (fn) {
        const args = []
        return function result(...rest) {
          if (rest.length === 0) {
            return fn(...args)
          } else {
            args.push(...rest)
            return result
          }
        }
      }
      const res = currying(sumFn)(1)(2)(3)()
      console.log(res)
    </script>
  </body>
</html>
